<?php

function makeBackButton() {
	if (count($_SESSION['back']) <= 1) {
		$gray = "disabled";
		
	} else {
		$gray = "";
		
	}
	global $prevPage, $prevSearch;
	
	echo "<form name=\"back\" action=\"" . $prevPage ."?". $prevSearch . "\" method=\"post\" >";
	echo "<font size=\"2\"><input $gray type=\"submit\" name=\"Back\" value=\"Back\" >"; 
	echo '</form>';
}


function unsetLastElements() {
		array_pop($_SESSION['back']);
}

//if(isset($_SESSION['back'])) {
//	$_SESSION['back'] = array();
//} 
if(isset($_POST['Back'])) { 
	//if(curPageName() != 'Update.php' && curPageName() != 'AdminUpdate.php') { //Only needs to run once if we aren't putting anything on the stack.'
		unsetLastElements(); //Runs twice each back.  First to pop off the link that was just added and then to pop off the page where are currently at.
		unsetLastElements();
	//}
}
if(isset($_SESSION['back']) && count($_SESSION['back']) >= 1) {
	$lastPage = end($_SESSION['back']);
	$prevPage = $lastPage->prevPage;
	$prevSearch = $lastPage->prevSearch;
	//echo "PrevPage is $prevPage prevSearch is $prevSearch";
}
if((curPageName() != 'Update.php' && curPageName() != 'AdminUpdate.php')) {
	$back = $_SESSION['back'];
	$back[] = new Back(curPageName(), $_SERVER['QUERY_STRING']);
	$_SESSION['back'] = $back;
}
unset($_POST['Back']);
?>